package com.rtp.transformer.fin.server.dao;

import java.util.List;

import org.hibernate.Criteria;

import com.rtp.transformer.fin.client.model.AccountCategory;
import com.rtp.transformer.fin.server.util.HibernateUtil;

public class FinDAO {

	private static FinDAO finDAO;
	public static FinDAO getInstance(){
		if(finDAO==null)
			finDAO=new FinDAO();
		return finDAO;
	}
	
	private FinDAO(){
		
	}
	/**
	 * 
	 * @return
	 */
	public List<AccountCategory> getAccountCategoryList(){
		return getAccountCategoryList(-1,-1);
	}
	/**
	 * 
	 * @param startIndex
	 * @param pageSize
	 * @return
	 */
	public List<AccountCategory> getAccountCategoryList(int startIndex,int pageSize){
		Criteria c = HibernateUtil.currentSession().createCriteria(AccountCategory.class);
		if(startIndex!=-1)
		c.setFirstResult(startIndex);
		if(pageSize!=-1)
		c.setMaxResults(pageSize);
//		c.setFetchMode("items", FetchMode.JOIN).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
//		List<AccountCategory> list = new ArrayList<AccountCategory>();
		List<AccountCategory> result = c.list();
		for (AccountCategory accountCategory : result) {
//			AccountCategory ac = new AccountCategory();
//			try {
//				BeanUtils.copyProperties(ac, accountCategory);
//			} catch (IllegalAccessException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			} catch (InvocationTargetException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
			accountCategory.setItems(null);
			 
		}		
		return result;
	}
}
